
layui.use(['jquery', 'febs', 'table', 'form'], function () {
        var $ = layui.jquery,
            form = layui.form,
            febs = layui.febs,
            table = layui.table,
            $view = $('#user-system-notice'),
            table_data = [];

            get_data();

        function get_data () {
            febs.get(ctx + 'notice/todoList', {}, function (result) {
                if (result.code == 200) {
                    table_data = result.data;
                    initTable();
                }
            });
        }

        // 表格
        function initTable() {
            table.render({
            elem: '#task_table',
            data: table_data,
            page: false,
            cols: [[
            {   field: 'createdTime', title: '发起时间', width: 170, align: 'center' },
            {   field: 'pendingType', title: '待办类型', width: 150, align: 'center' },
            {   field: 'noticeContent', title: '待办内容', align: 'center' },
            {   title: '操作', width: 100, align: 'center',
                templet: function (d) {
                    return `<span class="banli_btn" 
                    data-id="${ d.id }"
                    data-dealurl="${ d.url }"
                    data-index="${ d.LAY_INDEX }"
                    >办理/已读</span>`
                }
            }
            ]],
            done: function(res, curr, count, origin){}
            });
        }

        $view.on('click', '.banli_btn', function () {
            let id = $(this).data('id');
            let dealUrl = $(this).data('dealurl');
            let index = $(this).data('index');

            console.log('dealUrl--', dealUrl)
            febs.get(ctx + 'notice/done/' + id, {}, function (result) {
                if (result.code == 200) {
                    layer.msg('已读成功');
                    table_data.splice(index, 1);
                    if (dealUrl) {
                        layer.closeAll();
                        febs.navigate(dealUrl);
                    } else {
                        initTable();
                        // get_data();
                    }
                    $('#febs-layout').find('#layout_notice_num').text(table_data.length);
                }
            });
        })

        form.on('submit(user-system-notice-form-submit)', function (data) {
            febs.get(ctx + 'doneAll', {}, function (r) {
                if (result.code == 200) {
                    $('#febs-layout').find('#layout_notice_num').text(0);
                    layer.closeAll();
                    febs.modal.success('全部已读成功');
                }
            });
            return false;
        });
    });